<?php
$USER = &$GLOBALS['USER'];
if (check_action("user_login", 'post')) {
    $login = $_POST['login'];
    $pass = $_POST['pass'];
    $loginOk = false;
    $ok = true;
    $store = !empty($_POST['store']) ? true: false;
    
    if($store){
        setcookie("FROSTSTORE", Y);
    }else{
        setcookie("FROSTSTORE", false);
    }
    
    if(!empty($_POST['recaptcha_challenge_field'])){
        $ok = Recaptcha::Check($_POST['recaptcha_challenge_field'], $_POST['recaptcha_response_field']);
    }
    
    if ($ok) {
        $USER->Login($login, $pass)->isTrue();
    }    
    if ($USER->isAuth()) {
        if (!empty($params['login_page'])) {
            header("Location:" . $params['login_page']);
        } else {
            header("Location:" . $_SERVER['REQUEST_URI']);
        }
    } else {        
        Logger::error(t("Invalid login/pass"));
    }
}

if (check_action("user_logout", 'post')) {
    $USER->Logout();    
    if (!empty($params['login_page'])) {
        header("Location:" . $params['logout_page']);
    } else {
        header("Location:" . $_SERVER['REQUEST_URI']);
    }
}